package com.icare.shop.config;

import com.icare.shop.feign.TradeFeignService;
import com.icare.shop.utils.StaticUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.FeignClientBuilder;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;


/**
 * <pre>
 *    author  : tianhaibo
 *    email   : tianhaibo@jshuii.com
 *    time    : 2020/3/22   13:05
 *    desc    :
 *    version : v1.0
 * </pre>
 */
public class ShopAutoConfigration {

    private static final Log log = LogFactory.getLog(ShopAutoConfigration.class);


    @Bean
    public TradeFeignService initTradeFeignService(ApplicationContext context){
        log.info("初始化生成自动配置");
        //手动创建FeignClient
        FeignClientBuilder clientBuilder = new FeignClientBuilder(context);
        //获取feign类注解信息
        FeignClient annotation = TradeFeignService.class.getAnnotation(FeignClient.class);
        //取value属性
        FeignClientBuilder.Builder<TradeFeignService> feignServiceBuilder = clientBuilder.forType(TradeFeignService.class, annotation.value());
        TradeFeignService tradeFeignService = feignServiceBuilder.build();
        StaticUtil.initStaticUtil(tradeFeignService);
        return tradeFeignService;
    }

}


